﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;


public partial class IssueMsg : System.Web.UI.Page
{
    private string userName;
    
       
    protected void Page_Load(object sender, EventArgs e)
    {
        if(Session["userName"]!=null && Session["roleID"]!=null)
        {
          userName=Session["userName"].ToString();
          if(!IsPostBack)
           {
            lblUserName.Text = BasicClass.GetTrueNameByUserName(userName);
            BindDep();
            BindUser();
           }
        }
        else
        {
            Response.Redirect(GetUrlPath.GetUrl + "/Login.aspx");
        }

    }
    //发送信息
    protected void btnSend_Click(object sender, EventArgs e)
    {
        messages msg = new messages();
        msg.FromUserName = userName ;
        msg.ToUserName = Convert.ToString(ddlUserName.SelectedValue.ToString());
        msg.Title =BasicClass.HtmlEncode(txtTitle.Text);
        msg.Content =BasicClass.HtmlEncode(txtContent.Text);
        msg.SendDate = DateTime.Now;
        msg.ToUserStatus = 0;
        msg.FromUserStatus = 1;
        msg.TrueFlowID="0";
        if (msg.AddMsg())
        {
            Response.Write("<script langeuage='javascript'>alert('发送成功！')</script>");

        }
        else 
        {
            Response.Write("<script langeuage='javascript'>alert('发送失败！')</script>");
        }
       


    }
    //绑定部门
    protected void BindDep()
    {
       
       string strSearchAllDep = "select * from DEPARTMENT";
       DBOperation DB = new DBOperation();
       SqlDataReader sdr = DB.GetDataReader(strSearchAllDep);
       ddlDep.DataSource = sdr;
       ddlDep.DataTextField = "DEPNAME";
       ddlDep.DataValueField = "DEPID";
       ddlDep.DataBind();
       sdr.Close();

    }
    //绑定用户
    protected void BindUser()
    {
        string strSearchUser = "select TRUENAME ,USERNAME from USERS where DEPID='" + Convert.ToString(ddlDep.SelectedValue) + "' and USERNAME<>'admin'";
        DBOperation DB = new DBOperation();
        SqlDataReader sdr = DB.GetDataReader(strSearchUser);
        ddlUserName.DataSource = sdr;
        ddlUserName.DataTextField = "TRUENAME";
        ddlUserName.DataValueField = "USERNAME";
        ddlUserName.DataBind();
        sdr.Close();
        
    }
    protected void ddlDep_SelectedIndexChanged(object sender, EventArgs e)
    {
        BindUser();
       
    }
     protected void btnClear_Click(object sender, EventArgs e)
    {
        txtContent.Text = "";
    }
   
}
